package com.newtype.meeting.client.model;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.newtype.meeting.shared.AccountDTO;
import com.newtype.meeting.shared.AccountSummaryDTO;
import com.newtype.meeting.shared.AccountTreeDTO;

/**
 * 帐户实体类
 * @author 汪恭泽
 * Jun 3, 2011 9:40:03 AM
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Account implements Serializable {

	private static final long serialVersionUID = -2134772843835289768L;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String id;

	@Persistent(dependent = "true")
	private AccountDetails details;

	@Persistent
	private String status;//状态--->0:未开通,1:正常,2：停用
	@Persistent
	private String accountID;//帐号
	@Persistent
	private String password;//密码
	@Persistent
	private String fullName;//姓名
	@Persistent
	private String degree;//等級
	@Persistent
	private String title;//职称
	@Persistent
	private String deptID;//专职部门
	@Persistent
	private String email;//Email
	@Persistent
	private String phone;//行动电话
	@Persistent
	private String msn;//MSN
	@Persistent
	private String skype;//Skype

	@Persistent
	private AccountType accountType;//人员类型

	public Account() {
		details = new AccountDetails();
	}

	public Account(AccountDTO accountDTO) {
		this();
		this.setBasicInfo(accountDTO.getStatus(), accountDTO.getAccountID(),
				accountDTO.getPassword(), accountDTO.getFullName(), accountDTO
						.getDegree(), accountDTO.getTitle(), accountDTO
						.getDeptID(), accountDTO.getEmail(), accountDTO
						.getPhone(), accountDTO.getMsn(),
				accountDTO.getSkype(), accountDTO.getGender(), accountDTO
						.getBirthday(), accountDTO.getOfficePhoneNO(),
				accountDTO.getOfficephoneEXT(), accountDTO.getPager(),
				accountDTO.getHomePhoneNO(), accountDTO.getEmergencyContact(),
				accountDTO.getEmergencyPhoneNO(), accountDTO.getAddress(),
				accountDTO.getPersonIMG(), accountDTO.getIntroduces(),
				accountDTO.getSignIMG(), accountDTO.getWorkDuties(), accountDTO
						.getWorkStartTime(), accountDTO.getWorkEndTime(),
				accountDTO.getNotes(), accountDTO.getOpenTAG(), accountDTO
						.getOnlineDATE(), accountDTO.getByWorkDeptID(),
				accountDTO.getAccessErrorCount(), accountDTO.getModifyDate(),
				accountDTO.getRegisterDate(), accountDTO.getSubmitDate(),
				accountDTO.getAccountType());
	}

	public void setBasicInfo(String status, String accountID, String password,
			String fullName, String degree, String title, String deptID,
			String email, String phone, String msn, String skype,
			String gender, Date birthday, String officePhoneNO,
			String officephoneEXT, String pager, String homePhoneNO,
			String emergencyContact, String emergencyPhoneNO, String address,
			String personIMG, String introduces, String signIMG,
			String workDuties, Integer workStartTime, Integer workEndTime,
			String notes, String openTAG, Date onlineDATE, String byWorkDeptID,
			Integer accessErrorCount, Date modifyDate, Date registerDate,
			Date submitDate, AccountType accountType) {
		this.status = status;
		this.accountID = accountID;
		this.password = password;
		this.fullName = fullName;
		this.degree = degree;
		this.title = title;
		this.deptID = deptID;
		this.email = email;
		this.phone = phone;
		this.msn = msn;
		this.skype = skype;
		this.setGender(gender);
		this.setBirthday(birthday);
		this.setOfficePhoneNO(officePhoneNO);
		this.setOfficephoneEXT(officephoneEXT);
		this.setPager(pager);
		this.setHomePhoneNO(homePhoneNO);
		this.setEmergencyContact(emergencyContact);
		this.setEmergencyPhoneNO(emergencyPhoneNO);
		this.setAddress(address);
		this.setPersonIMG(personIMG);
		this.setIntroduces(introduces);
		this.setSignIMG(signIMG);
		this.setWorkDuties(workDuties);
		this.setWorkStartTime(workStartTime);
		this.setWorkEndTime(workEndTime);
		this.setNotes(notes);
		this.setOpenTAG(openTAG);
		this.setOnlineDATE(onlineDATE);
		this.setByWorkDeptID(byWorkDeptID);
		this.setAccessErrorCount(accessErrorCount);
		this.setModifyDate(modifyDate);
		this.setRegisterDate(registerDate);
		this.setSubmitDate(submitDate);
		this.setAccountType(accountType);
	}

	public AccountDTO toDTO() {
		AccountDTO accountDTO = new AccountDTO(this.getAccountID(), this
				.getPassword(), this.getFullName(), this.getEmail(), this
				.getPhone());
		accountDTO.setId(this.getId());
		accountDTO.setStatus(this.getStatus());
		accountDTO.setDegree(this.getDegree());
		accountDTO.setTitle(this.getTitle());
		accountDTO.setDeptID(this.getDeptID());
		accountDTO.setMsn(this.getMsn());
		accountDTO.setSkype(this.getSkype());
		accountDTO.setGender(this.getGender());
		accountDTO.setBirthday(this.getBirthday());
		accountDTO.setOfficePhoneNO(this.getOfficePhoneNO());
		accountDTO.setOfficephoneEXT(this.getOfficephoneEXT());
		accountDTO.setPager(this.getPager());
		accountDTO.setHomePhoneNO(this.getHomePhoneNO());
		accountDTO.setEmergencyContact(this.getEmergencyContact());
		accountDTO.setEmergencyPhoneNO(this.getEmergencyPhoneNO());
		accountDTO.setAddress(this.getAddress());
		accountDTO.setPersonIMG(this.getPersonIMG());
		accountDTO.setIntroduces(this.getIntroduces());
		accountDTO.setSignIMG(this.getSignIMG());
		accountDTO.setWorkDuties(this.getWorkDuties());
		accountDTO.setWorkStartTime(this.getWorkStartTime());
		accountDTO.setWorkEndTime(this.getWorkEndTime());
		accountDTO.setNotes(this.getNotes());
		accountDTO.setOpenTAG(this.getOpenTAG());
		accountDTO.setOnlineDATE(this.getOnlineDATE());
		accountDTO.setByWorkDeptID(this.getByWorkDeptID());
		accountDTO.setAccessErrorCount(this.getAccessErrorCount());
		accountDTO.setModifyDate(this.getModifyDate());
		accountDTO.setRegisterDate(this.getRegisterDate());
		accountDTO.setSubmitDate(this.getSubmitDate());
		accountDTO.setAccountType(this.getAccountType());

		return accountDTO;
	}

	/**
	 * 更新已存在的帐户信息，根据account DTO id
	 * @param accountDTO
	 */
	public void updateFromDTO(AccountDTO accountDTO) {
		this.status = accountDTO.getStatus();
		this.accountID = accountDTO.getAccountID();
		this.password = accountDTO.getPassword();
		this.fullName = accountDTO.getFullName();
		this.degree = accountDTO.getDegree();
		this.title = accountDTO.getTitle();
		this.deptID = accountDTO.getDeptID();
		this.email = accountDTO.getEmail();
		this.phone = accountDTO.getPhone();
		this.msn = accountDTO.getMsn();
		this.skype = accountDTO.getSkype();
		this.setGender(accountDTO.getGender());
		this.setBirthday(accountDTO.getBirthday());
		this.setOfficePhoneNO(accountDTO.getOfficePhoneNO());
		this.setOfficephoneEXT(accountDTO.getOfficephoneEXT());
		this.setPager(accountDTO.getPager());
		this.setHomePhoneNO(accountDTO.getHomePhoneNO());
		this.setEmergencyContact(accountDTO.getEmergencyContact());
		this.setEmergencyPhoneNO(accountDTO.getEmergencyPhoneNO());
		this.setAddress(accountDTO.getAddress());
		this.setPersonIMG(accountDTO.getPersonIMG());
		this.setIntroduces(accountDTO.getIntroduces());
		this.setSignIMG(accountDTO.getSignIMG());
		this.setWorkDuties(accountDTO.getWorkDuties());
		this.setWorkStartTime(accountDTO.getWorkStartTime());
		this.setWorkEndTime(accountDTO.getWorkEndTime());
		this.setNotes(accountDTO.getNotes());
		this.setOpenTAG(accountDTO.getOpenTAG());
		this.setOnlineDATE(accountDTO.getOnlineDATE());
		this.setByWorkDeptID(accountDTO.getByWorkDeptID());
		this.setAccessErrorCount(accountDTO.getAccessErrorCount());
		this.setModifyDate(accountDTO.getModifyDate());
		this.setRegisterDate(accountDTO.getRegisterDate());
		this.setSubmitDate(accountDTO.getSubmitDate());
		this.setAccountType(accountDTO.getAccountType());
	}

	public AccountSummaryDTO toLightWeightDTO() {
		return new AccountSummaryDTO(id, getAccountID(), getFullName(),
				getGender(), getOnlineDATE(), getRegisterDate(), getDeptID(),
				getTitle(), getStatus());
	}

	public AccountTreeDTO toLightTreeDTO(Department dept) {
		return new AccountTreeDTO(getId(), getAccountID(), getFullName(), dept
				.getDeptName());
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getAccountID() {
		return accountID;
	}

	public void setAccountID(String accountID) {
		this.accountID = accountID;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	public String getDegree() {
		return degree;
	}

	public void setDegree(String degree) {
		this.degree = degree;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDeptID() {
		return deptID;
	}

	public void setDeptID(String deptID) {
		this.deptID = deptID;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getMsn() {
		return msn;
	}

	public void setMsn(String msn) {
		this.msn = msn;
	}

	public String getSkype() {
		return skype;
	}

	public void setSkype(String skype) {
		this.skype = skype;
	}

	public String getId() {
		return id;
	}

	public AccountType getAccountType() {
		return accountType;
	}

	public void setAccountType(AccountType accountType) {
		this.accountType = accountType;
	}

	public AccountDetails getDetails() {
		return details;
	}

	public void setDetails(AccountDetails details) {
		this.details = details;
	}

	/* ---------------------------------------------------*/
	public void setGender(String gender) {
		details.setGender(gender);
	}

	public void setBirthday(Date birthday) {
		details.setBirthday(birthday);
	}

	public void setOfficePhoneNO(String officePhoneNO) {
		details.setOfficePhoneNO(officePhoneNO);
	}

	public void setOfficephoneEXT(String officephoneEXT) {
		details.setOfficephoneEXT(officephoneEXT);
	}

	public void setPager(String pager) {
		details.setPager(pager);
	}

	public void setHomePhoneNO(String homePhoneNO) {
		details.setHomePhoneNO(homePhoneNO);
	}

	public void setEmergencyContact(String emergencyContact) {
		details.setEmergencyContact(emergencyContact);
	}

	public void setEmergencyPhoneNO(String emergencyPhoneNO) {
		details.setEmergencyPhoneNO(emergencyPhoneNO);
	}

	public void setAddress(String address) {
		details.setAddress(address);
	}

	public void setPersonIMG(String personIMG) {
		details.setPersonIMG(personIMG);
	}

	public void setIntroduces(String introduces) {
		details.setIntroduces(introduces);
	}

	public void setSignIMG(String signIMG) {
		details.setSignIMG(signIMG);
	}

	public void setWorkDuties(String workDuties) {
		details.setWorkDuties(workDuties);
	}

	public void setWorkStartTime(Integer workStartTime) {
		details.setWorkStartTime(workStartTime);
	}

	public void setWorkEndTime(Integer workEndTime) {
		details.setWorkEndTime(workEndTime);
	}

	public void setNotes(String notes) {
		details.setNotes(notes);
	}

	public void setOpenTAG(String openTAG) {
		details.setOpenTAG(openTAG);
	}

	public void setOnlineDATE(Date onlineDATE) {
		details.setOnlineDATE(onlineDATE);
	}

	public void setByWorkDeptID(String byWorkDeptID) {
		details.setByWorkDeptID(byWorkDeptID);
	}

	public void setAccessErrorCount(Integer accessErrorCount) {
		details.setAccessErrorCount(accessErrorCount);
	}

	public void setModifyDate(Date modifyDate) {
		details.setModifyDate(modifyDate);
	}

	public void setRegisterDate(Date registerDate) {
		details.setRegisterDate(registerDate);
	}

	public void setSubmitDate(Date submitDate) {
		details.setSubmitDate(submitDate);
	}

	public Account getAccount() {
		return details.getAccount();
	}

	public String getGender() {
		return details.getGender();
	}

	public Date getBirthday() {
		return details.getBirthday();
	}

	public String getOfficePhoneNO() {
		return details.getOfficePhoneNO();
	}

	public String getOfficephoneEXT() {
		return details.getOfficephoneEXT();
	}

	public String getPager() {
		return details.getPager();
	}

	public String getHomePhoneNO() {
		return details.getHomePhoneNO();
	}

	public String getEmergencyContact() {
		return details.getEmergencyContact();
	}

	public String getEmergencyPhoneNO() {
		return details.getEmergencyPhoneNO();
	}

	public String getAddress() {
		return details.getAddress();
	}

	public String getPersonIMG() {
		return details.getPersonIMG();
	}

	public String getIntroduces() {
		return details.getIntroduces();
	}

	public String getSignIMG() {
		return details.getSignIMG();
	}

	public String getWorkDuties() {
		return details.getWorkDuties();
	}

	public Integer getWorkStartTime() {
		return details.getWorkStartTime();
	}

	public Integer getWorkEndTime() {
		return details.getWorkEndTime();
	}

	public String getNotes() {
		return details.getNotes();
	}

	public String getOpenTAG() {
		return details.getOpenTAG();
	}

	public Date getOnlineDATE() {
		return details.getOnlineDATE();
	}

	public String getByWorkDeptID() {
		return details.getByWorkDeptID();
	}

	public Integer getAccessErrorCount() {
		return details.getAccessErrorCount();
	}

	public Date getModifyDate() {
		return details.getModifyDate();
	}

	public Date getRegisterDate() {
		return details.getRegisterDate();
	}

	public Date getSubmitDate() {
		return details.getSubmitDate();
	}
}
